package cn.kmia.hrm.action.basicData;


import cn.kmia.hrm.pojo.PostLinkInfo;
import cn.kmia.hrm.pojo.PostNatureInfo;
import cn.kmia.hrm.pojo.system.User;
import cn.kmia.hrm.service.basicData.PostNatureInfoService;
import cn.kmia.hrm.util.CommonSet;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.lang.util.PageInfo;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Scope;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Attr;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.util.List;

/**
 * @program: hrm
 * @description: 岗位属性信息操作
 * @author: lmx
 * @create: 2018/8/21 11:39
 **/
@IocBean
@At("/postNatureInfo")
public class PostNatureInfoAction {
    private static final Log log = Logs.get();

    @Inject
    protected PostNatureInfoService postNatureInfoService;
    /**
    * @Description: 新增 PostNatureInfo 并返回PostNatureInfo
    * @param  [postNatureInfo, user]
    * @return java.lang.Object
    * @throws
    * @author lmx
    * @date 2018/8/21 16:56
    */
    @At("/add")
    @Ok("json:full")
    @RequiresPermissions("postNatureInfo:add")
    public Object add(@Param("..") PostNatureInfo postNatureInfo, @Attr(scope = Scope.SESSION, value = "user") User user){
        NutMap nm = new NutMap();
        postNatureInfo = postNatureInfoService.add(postNatureInfo,user.getUser_idcard());
        if(postNatureInfo == null){
            nm.setv("sucess",false).setv("errorMsg","新增失败");
        } else{
            nm.setv("success",true).setv("obj",postNatureInfo);
        }
        return nm;
    }

    /**
    * @Description: 更新postNatureInfo 后返回该对象
    * @param  [postNatureInfo, user]
    * @return java.lang.Object
    * @throws
    * @author lmx
    * @date 2018/8/23 13:39
    */
    @At("/update")
    @Ok("json:full")
    @RequiresPermissions("postNatureInfo:update")
    public Object update(@Param("..") PostNatureInfo postNatureInfo,@Attr(scope = Scope.SESSION, value = "user") User user){
        NutMap nm = new NutMap();
        try {
            if(postNatureInfoService.update(postNatureInfo,user.getUser_idcard())){
                nm.setv("success",true);
            }else{
                nm.setv("success",false);
            }
        } catch (Exception e) {
            nm.setv("success",false);
            log.error("更新异常",e);
        }
        return  nm;
    }

    /**
    * @Description: 删除postNatureInfo对象
    * @param  [ids]
    * @return java.lang.Object
    * @throws
    * @author lmx
    * @date 2018/8/23 14:28
    */
    @At("/del")
    @Ok("json:full")
    @RequiresPermissions("postNatureInfo:del")
    public Object del(@Param("ids") int[] ids){
        NutMap nm = new NutMap();
        try {
            if(ids != null){
                nm = postNatureInfoService.del(ids);
            }else {
                nm.setv("success",false);
            }
        } catch (Exception e) {
            nm.setv("success",false);
            log.error("删除异常",e);
        }
        return  nm;
    }

    /**
    * @Description: 分页查询
    * @param  [page, natureName]
    * @return java.lang.Object
    * @throws
    * @author lmx
    * @date 2018/8/23 15:25
    */
    @At
    @Ok("json:full")
    @RequiresPermissions("postNatureInfo:queryByPage")
    public Object queryByPage(@Param("..") Pager page,@Param("name") String  natureName){
        NutMap nm = new NutMap();
        QueryResult qr = postNatureInfoService.queryByPage(page,natureName);
        nm.setv("rows",qr.getList());
        nm.setv("total",qr.getPager().getRecordCount());
        return nm;
    }

    /**
    * @Description: 一般查询
    * @param  [natureName]
    * @return java.util.List<cn.kmia.hrm.pojo.PostNatureInfo>
    * @throws
    * @author lmx
    * @date 2018/8/23 15:33
    */
    @At("/query")
    @Ok("json:full")
    public List<PostNatureInfo> query(@Param("name") String natureName){
        return postNatureInfoService.query(natureName);
    }

    /**
    * @Description: 查询岗位属性信息
    * @param  []
    * @return java.lang.Object
    * @throws
    * @author lmx
    * @date 2018/8/23 15:34
    */
    @At("/queryPostNatureInfo")
    @Ok("json:full")
    public Object queryPostNatureInfo(){
        return CommonSet.PostNatureInfo;
    }

    /**
    * @Description: 更新岗位属性信息
    * @param  []
    * @return java.lang.Object
    * @throws
    * @author lmx
    * @date 2018/8/23 15:45
    */
    @At("/updatePostLNatureInfo")
    @Ok("json:full")
    public Object updatePostLNatureInfo(){
        NutMap nm = new NutMap();
        try {
            postNatureInfoService.updatePostNatureInfo();
            nm.setv("success",true);
        } catch (Exception e) {
            nm.setv("success",false).setv("errorMsg",e);
        }
        return nm;
    }

}
